//爱吃素
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        while (t--  0) {
            long a = in.nextLong();
            long b = in.nextLong();
            if (a == 1  b == 1) {
                if (a == 1) {
                    System.out.println(fun(b) == true  YES  NO);
                } else {
                    System.out.println(fun(a) == true  YES  NO);
                }
            } else {
                System.out.println(NO);   
            }
        }
    }
    
    static boolean fun(long a) {
        if (a == 1) {
            return false;
        }
        for (int i = 2; i = Math.sqrt(a); i++) {
            if (a % i == 0) {
                return false;
            }
        }
        return true;
    }
}